import bloomers.User
import bloomers.Seedz

class BootStrap {

    def init = { servletContext ->
        
        def user = new User(email:"user@user.com", password:"password", role:"user", firstName:"Bob", lastName:"", gender:"M", city:"", state:"", country:"", zipcode:"").save()
        
        def admin = new User(email:"admin@bloomersseeds.com", password:"admin", role:"admin", firstName:"Admin", lastName:"", gender:"M", city:"", state:"", country:"", zipcode:"").save()
        
        def seed = new Seedz(annual: "annual", genus: "a", species: "b", seedName: "corn", variety: "yellow", forma: "sweet", hardiness: "1").save()
        
        def dataList = []
        
        def usersFile = new File( '/Users/hryals3/NetBeansProjects/Bloomers/grails-app/conf/Resources/bloomersUsers.txt' )
        def seedzFile = new File( '/Users/hryals3/NetBeansProjects/Bloomers/grails-app/conf/Resources/bloomersSeedz.txt' )

        if( !usersFile.exists() ) {
            println "File does not exist"
        } 
        else {
            def driveInfo = [:]
            // Step through each line in the file
            usersFile.eachLine { line ->
                // If the line isn't blank
                if( line.trim() ) {
                    // Split into a key and value
                    def userFields = line.split( '\t' ).collect { it.trim() }
                    new User(email: userFields[0],
                    password: userFields[1],
                    role: userFields[2],
                    firstName: userFields[3],
                    lastName: userFields[4],
                    gender: userFields[5],
                    city: userFields[6],
                    state: userFields[7],
                    country: userFields[8],
                    zipcode: userFields[9]).save()
                    
                    println userFields
                    
                }
            }
        }
        
        if( !seedzFile.exists() ) {
            println "File does not exist"
        } 
        else {
            def driveInfo = [:]
            // Step through each line in the file
            seedzFile.eachLine { line ->
                // If the line isn't blank
                if( line.trim() ) {
                    // Split into values by tabs
                    def seedzFields = line.split( '\t' ).collect { it.trim() }
                    new Seedz(annual: seedzFields[0],
                    genus: seedzFields[1],
                    species: seedzFields[2],
                    seedName: seedzFields[3],
                    variety: seedzFields[4],
                    forma: seedzFields[5],
                    hardiness: seedzFields[6]).save()
                    
                    println seedzFields
                    
                }
            }
        }
    }
  
    def destroy = {
        
        println()
    }
}
